package com.example.globalcontrol.inteceptor;

import com.example.modelfunction.shrio.usermanager.mode.User;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyIncerteptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("进入拦截器:"+request.getRequestURI());
        if("/error".equalsIgnoreCase(request.getRequestURI())) {
            System.out.println("进入拦截器追踪:"+request.getRequestURI());
        }
        if("/msg".equalsIgnoreCase(request.getRequestURI())) {
            System.out.println("进入拦截器追踪:"+request.getRequestURI());
        }
        String sessionId= (String) SecurityUtils.getSubject().getSession().getId();
        User user= (User) SecurityUtils.getSubject().getSession().getAttribute("user");
//        if(user==null){
////            response.sendRedirect(request.getContextPath() + "/static/index.html");
//            response.sendRedirect(request.getContextPath() + "/login.html");
//            return false;
//        }
     /*   HttpSession session = request.getSession();
        Admin user = (Admin) request.getSession().getAttribute("ADMIN_ACCOUNT");
        if (user == null) {
            //用户为空，重新登录
            response.sendRedirect(request.getContextPath() + "/login.html");
            return false;
        }*/
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
